/**
 * Created with IntelliJ IDEA.
 * Description:
 * Date: 2025-06-18
 * Time: 17:56
 */
//力扣852.山脉数组的峰顶索引
class Solution {

    public int peakIndexInMountainArray(int[] arr) {
        int left = 1;//小优化 最后一个和第一个一定不是最后峰值
        int right = arr.length - 2;

        while (left < right) {
            int mid = left + (right - left + 1) / 2;

            //将山峰分为两个区间 看看mid落在哪个区间就通过哪个区间来判断
            if (arr[mid] >= arr[mid - 1]) {
                left = mid;
            }else {
                right = mid - 1;
            }
        }

        return left;
    }
}
